package my.edu.utils;

import org.springframework.stereotype.Component;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.Year;
import java.time.YearMonth;

public class TimeUtil {
    public static LocalDateTime getTodayStartTime() {
        LocalDateTime now = LocalDateTime.now();
        return now.withHour(0).withMinute(0).withSecond(0).withNano(0);
    }
    public static LocalDateTime getTodayEndTime() {
        LocalDateTime now = LocalDateTime.now();
        return now.withHour(23).withMinute(59).withSecond(59).withNano(999999999);
    }

    public static LocalDateTime getDayStartTime(LocalDateTime localDateTime) {
        return localDateTime.withHour(0).withMinute(0).withSecond(0).withNano(0);
    }
    public static LocalDateTime getDayEndTime(LocalDateTime localDateTime) {
        return localDateTime.withHour(23).withMinute(59).withSecond(59).withNano(999999999);
    }

    public static LocalDateTime getStartOfYear() {
        return Year.now().atDay(1).atStartOfDay();
    }

    public static LocalDateTime getStartOfMonth() {
        // 获取当前月份的第一天和最后一天
        return YearMonth.now().atDay(1).atStartOfDay();
    }

    public static LocalDateTime getEndOfMonth() {
        return YearMonth.now().atEndOfMonth().atStartOfDay();
    }
}
